<template>
    <div class="menus-body" @mouseleave ="out">
        <div class="menus">
            <div class="menu-item" 
            v-for="(item, index) in AsideCity" 
            :key="index" 
            :class="{activ:getIndex == index}"
            @mouseenter="getItem(item,index)" >
                {{item.type}}
            </div>
        </div>
        <div class="sub-menus" v-if="flag">
            <ul>
                <li v-for="(item, index) in getChildren" :key="index">
                    <a href="javascript:void(0)" @click="changeRoutr(item)">
                      <i>{{index + 1}}</i>
                      <strong>{{item.city}}</strong>
                      <span>{{item.desc}}</span>
                    </a>
                </li>
            </ul>
        </div>
    </div>
</template>

<script>
export default {
    data(){
        return{
            AsideCity:"",
            getIndex:null,
            getChildren:null,
            flag:false
        }
    },
    created(){
        // console.log(this.$route);
        this.$axios({
            url:'/posts/cities',
        }).then(res=>{
            console.log(res.data);
            this.AsideCity = res.data.data
            
        })
    },
    methods:{
        getItem(item,index){
 
            this.getChildren = item.children
            this.getIndex = index 
            this.flag = true
        },
        out(){
            this.flag = false
            this.getIndex = null
        },
        changeRoutr(item){
          this.$router.push(`post?city=${item.city}&start=${this.$route.query.start}&limit=${this.$route.query.limit}`)
          this.$emit('bbbb',item.city)
        }
    }
}
</script>
<style lang="less" scoped>
.menus-body{
    position: relative;
    z-index: 2;
}
.menus{
    
    width: 260px;
    border: 1px solid #dddddd;
    z-index: 2;
    border-right: none;
    border-bottom: none;
    position: relative;
    
    .menu-item{
        height: 40px;
        line-height: 40px;
        border-right: 1px solid #dddddd;
        border-bottom: 1px solid #dddddd;
        padding: 0 20px;
        font-size: 14px;
        box-sizing: border-box;
        z-index: 2;
        background: #fff;
        
    }
    .activ{
      border-right: none ;
      color: orange;
    }
}
.sub-menus{
    position: absolute;
    left: 260px;
    top: 0;
    width: 350px;
    padding: 10px 20px;
    box-sizing: border-box;
    background: #fff;
    border: 1px solid #dddddd;
    box-sizing: border-box;
    
    

    ul{
        li{
          font-size: 14px;
          line-height: 1.5;
            a{
              i{
                  color: orange;
                  font-size: 24px;
                  font-style: italic;
                  
              }
              strong{
                  font-weight: 400;
                  color: orange;
                  margin: 0 10px;
                  &:hover{
                    text-decoration: underline;
                  }
              }
              span{
                  color: #666;
                  &:hover{
                    text-decoration: underline;
                  }
              }
            }

        }
    }
}


</style>